<template>
    <!-- 添加或修改发放打款明细信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="发放日期" prop="grantDate">
                                <el-date-picker clearable
                                                v-model="form.grantDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择发放日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="发放金额" prop="grantMoney">
                              <el-input-number :precision="2" :min="0" v-model="form.grantMoney" placeholder="请输入发放金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="发放公司" prop="companyName">
                              <el-select v-model="form.companyName" placeholder="请选择发放公司" clearable style="width: 300px">
                                <el-option v-for="dict in dict.type.company"
                                           :key="dict.value" :label="dict.label" :value="dict.value"/>
                              </el-select>
<!--                                <el-input v-model="form.companyName" placeholder="请输入发放标识"/>-->
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item label="发放记录" prop="companyId">
                            <image-upload v-model="form.companyId"/>
                          </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="备注" prop="remark">
                                <el-input type="textarea"  v-model="form.remark" placeholder="请输入备注"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { addAction, getAction, getById, updateAction } from '@/api/manage'
    import moment from 'moment';

    export default {
        name: "GoodsReimbursementDetailForm",
        dicts:['company'],
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                  grantMoney: [
                    { required: true, message: "发放金额不能为空", trigger: "blur" }
                  ],
                  companyName: [
                    { required: true, message: "发放乙方不能为空", trigger: "blur" }
                  ],
                },
                url: {
                    getById:'/goodsReimbursementDetail/goodsReimbursementDetail/',
                    add:'/goodsReimbursementDetail/goodsReimbursementDetail/add',
                    edit:'/goodsReimbursementDetail/goodsReimbursementDetail/edit',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                  id: null,
                  reimburseId: null,
                  userId: null,
                  userName: null,
                  grantDate: new Date(),
                  grantMoney: null,
                  companyId: null,
                  companyName: null,
                  status: "0",
                  delFlag: null,
                  createBy: null,
                  createTime: null,
                  updateBy: null,
                  updateTime: null,
                  remark: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd(reimburse) {
                let that = this;
                that.reset();
                that.form.reimburseId = reimburse.id;
                if(reimburse.remCompany){
                    that.form.companyName = reimburse.remCompany;
                }
                if(reimburse.remRemain){
                    that.form.grantMoney = reimburse.remRemain;
                }
                that.open = true;
                that.title = "添加发放打款明细信息管理";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改发放打款明细信息管理";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
